//
//  CollectionViewItemCell.m
//  SeplitDemo
//
//  Created by 信恩世通 on 2017/8/1.
//  Copyright © 2017年 Xiyuekeji. All rights reserved.
//

#import "CollectionViewItemCell.h"

#import "GoodsModel.h"

@interface CollectionViewItemCell ()

/** 图片 */
@property (strong, nonatomic) UIImageView *iconView;
/** 价格 */
@property (strong, nonatomic) UILabel *priceLab;

@end

@implementation CollectionViewItemCell

#pragma mark - **** instance ****

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self addSubview:iconView];
        self.iconView = iconView;
        
        UILabel *priceLab = [[UILabel alloc] initWithFrame:CGRectZero];
        priceLab.textColor = COLOR_TEXT_HIGHT;
        priceLab.textAlignment = NSTextAlignmentCenter;
        priceLab.font = Font(15.0f);
        priceLab.baselineAdjustment = UIBaselineAdjustmentNone;
        [self addSubview:priceLab];
        self.priceLab = priceLab;
        
        [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self);
            make.centerX.mas_equalTo(self);
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(80);
        }];
        
        [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.iconView.mas_bottom).offset(5.0f);
            make.left.mas_equalTo(self.mas_left).offset(5.0f);
            make.right.mas_equalTo(self.mas_right).offset(-5.0f);
        }];
        
        self.backgroundColor = COLOR_WHITE;
    }
    return self;
}

#pragma mark - **** setting ****

- (void)setGoodsItemDic:(NSDictionary *)goodsItemDic {
    _goodsItemDic = goodsItemDic;
    self.priceLab.text = [NSString stringWithFormat:@"$ %.2f",[goodsItemDic[@"Price"] floatValue]];
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:goodsItemDic[@"ProductImg"]] placeholderImage:[UIImage imageNamed:@"default60"]];
}



@end
